package com.ruoyi.kk.vehicle.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kk.vehicle.domain.KkUserVehicleInfo;
import com.ruoyi.kk.vehicle.service.IKkUserVehicleInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户车辆信息Controller
 * 
 * @author kk
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/kk/vehicle")
public class KkUserVehicleInfoController extends BaseController
{
    @Autowired
    private IKkUserVehicleInfoService kkUserVehicleInfoService;

    /**
     * 查询用户车辆信息列表
     */
    @PreAuthorize("@ss.hasPermi('kk:vehicle:list')")
    @GetMapping("/list")
    public TableDataInfo list(KkUserVehicleInfo kkUserVehicleInfo)
    {
        startPage();
        kkUserVehicleInfo.setUserId(getUserId());
        List<KkUserVehicleInfo> list = kkUserVehicleInfoService.selectKkUserVehicleInfoList(kkUserVehicleInfo);
        return getDataTable(list);
    }

    /**
     * 导出用户车辆信息列表
     */
    @PreAuthorize("@ss.hasPermi('kk:vehicle:export')")
    @Log(title = "用户车辆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KkUserVehicleInfo kkUserVehicleInfo)
    {
        kkUserVehicleInfo.setUserId(getUserId());
        List<KkUserVehicleInfo> list = kkUserVehicleInfoService.selectKkUserVehicleInfoList(kkUserVehicleInfo);
        ExcelUtil<KkUserVehicleInfo> util = new ExcelUtil<KkUserVehicleInfo>(KkUserVehicleInfo.class);
        util.exportExcel(response, list, "用户车辆信息数据");
    }

    /**
     * 获取用户车辆信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('kk:vehicle:query')")
    @GetMapping(value = "/{vehicleId}")
    public AjaxResult getInfo(@PathVariable("vehicleId") Long vehicleId)
    {
        return success(kkUserVehicleInfoService.selectKkUserVehicleInfoByVehicleId(vehicleId));
    }

    /**
     * 新增用户车辆信息
     */
    @PreAuthorize("@ss.hasPermi('kk:vehicle:add')")
    @Log(title = "用户车辆信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KkUserVehicleInfo kkUserVehicleInfo)
    {
        kkUserVehicleInfo.setUserId(getUserId());
        kkUserVehicleInfo.setCreatedTime(DateUtils.getCurrDate());
        // todo 后续补充逻辑
        kkUserVehicleInfo.setVehiclePhoto("{}");
        return toAjax(kkUserVehicleInfoService.insertKkUserVehicleInfo(kkUserVehicleInfo));
    }

    /**
     * 修改用户车辆信息
     */
    @PreAuthorize("@ss.hasPermi('kk:vehicle:edit')")
    @Log(title = "用户车辆信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KkUserVehicleInfo kkUserVehicleInfo)
    {
        kkUserVehicleInfo.setUpdatedTime(DateUtils.getCurrDate());
        return toAjax(kkUserVehicleInfoService.updateKkUserVehicleInfo(kkUserVehicleInfo));
    }

    /**
     * 删除用户车辆信息
     */
    @PreAuthorize("@ss.hasPermi('kk:vehicle:remove')")
    @Log(title = "用户车辆信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vehicleIds}")
    public AjaxResult remove(@PathVariable Long[] vehicleIds)
    {
        return toAjax(kkUserVehicleInfoService.deleteKkUserVehicleInfoByVehicleIds(vehicleIds));
    }
}
